/*********************************************************************************************************
 * Copyright (c) 2017,深圳科陆电子科技股份有限公司
 * All rights reserved.
 *
 * 文件名称:public class ${jName}{ } 
 * 
 * 摘    要： 
 * 版    本：1.0
 * 作    者：${createBy}
 * 创建于：${createDate}
 * 最后修改时间：
 * 
 *********************************************************************************************************/
package com.power7000.service.impl.publics.${packageName};

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.power7000.model.publics.${packageName}.${jName};
import com.power7000.service.publics.${packageName}.${jName}Service;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Test${jName}ServiceImpl {
// 服务对象
	private static ${jName}Service ${jPname}Service = new ${jName}ServiceImpl();

	// 模型对象
	private static ${jName} ${jPname} = new ${jName}();

	// id集合
	private static String[] ids = null;

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		// 初始化环境
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"classpath:META-INF/spring/applicationContext.xml");
		com.power7000.core.util.context.ContextUtil.setContext(context);

		// 初始化模型对象
	}

	@Ignore
	@Test
	public void testPublicUserResidentServiceImpl() {
		fail("Not yet implemented");
	}


	@Test
	public void test001_Create${jName}() throws Exception {
		boolean target = true;// 期待目标值
		boolean result = false;// 实际运行结果值

		// 准备数据
		<#list paramList as param>  
		${jPname}.set${param["jFname"]}((${param["jType"]})"${param["jComment"]}");
   		</#list>
		// 执行测试
		String sid = ${jPname}Service.create${jName}(${jPname});
		result = (sid!=null);
		
		// 比对结果
		assertEquals(target, result);
	}
	
	
	
	@Test
	public void test002_Find${jName}ById() throws Exception {
		boolean target = true;//期待目标值
		boolean result = false;//实际运行结果值
		
		//准备数据
		String idString ="USER00002CW6";
		//执行测试
		result = (${jPname}Service.find${jName}ById(idString)!=null);
		
		//比对结果
		assertEquals(target, result); 
	}
	
	@Test
	public void test003_Find${jName}ForJqGrid() throws Exception {
		boolean target = true;//期待目标值
		boolean result = false;//实际运行结果值
		
		//准备数据
		String jsonParam = "{";
		<#list paramList as param>  
		<#if (param_index==0)>jsonParam+="\"${param["jName"]}\":\"${param["jComment"]}\"";<#else>
		jsonParam+=",\"${param["jName"]}\":\"${param["jComment"]}\"";</#if>
   		</#list>
   		jsonParam+="}";
		int pageSize = 10;//每页数据行数
		int pageNo = 1;//页码
		
		//执行测试
		
		String jqGridData = ${jPname}Service.find${jName}ForJqGrid(jsonParam, pageSize, pageNo);
		result = (jqGridData!=null && jqGridData.indexOf("\"total\":0")==-1);
		
		System.out.println(jqGridData);
		
		//比对结果
		assertEquals(target, result); 
	}
	
	
	@Test
	public void test006_update${jName}() throws Exception {
		boolean target = true;//期待目标值
		boolean result = false;//实际运行结果值
		
		//准备数据
		<#list paramList as param>  
		${jPname}.set${param["jFname"]}((${param["jType"]})"${param["jComment"]}");
   		</#list>
		result = ${jPname}Service.update${jName}(${jPname});
		
		//比对结果
		assertEquals(target, result); 
	}
	
	@Test
	public void test07_delete${jName}ById() throws Exception {
		boolean target = true;//期待目标值
		boolean result = false;//实际运行结果值
		
		//准备数据

		//执行测试		
		for (int i = 0; i < ids.length; i++) {
			result = ${jPname}Service.delete${jName}ById(ids[i]);
		}
		
		//比对结果
		assertEquals(target, result); 
	}


	@Ignore
	@Test
	public void test08_Create${jName}Batch() {
		fail("Not yet implemented");
	}
	@Test
	public void test09_Delete${jName}ByIds() {
		fail("Not yet implemented");
	}
	
	
	
	
}
		